home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2004 #2 / Amiga Plus CD - 2004 - No. 02.iso / AmiSoft / Dev / misc / WHDLoad_dev.lha / WHDLoad / Src / programs / DIC.asm < prev    next >
Encoding:
Assembly Source File  |  2003-06-15  |  16.2 KB  |  782 lines

  1. ;*---------------------------------------------------------------------------
  2. ;  :Program.    DIC.asm
  3. ;  :Contents.    Disk-Image-Creator
  4. ;  :Author.    Bert Jahn
  5. ;  :EMail.    wepl@kagi.com
  6. ;  :Address.    Franz-Liszt-Straße 16, Rudolstadt, 07404, Germany
  7. ;  :Version.    $Id: DIC.asm 0.21 2003/06/14 20:17:42 wepl Exp wepl $
  8. ;  :History.    15.05.96
  9. ;        20.06.96 returncode supp.
  10. ;        01.06.97 _LVOWaitForChar added,  check for interactive terminal added
  11. ;        17.09.98 after a disk read error and 'cancel' it does not continue
  12. ;             if last disk already reached now (reported by MrLarmer)
  13. ;        12.10.98 bugfix
  14. ;        17.01.99 recompile because error.i changed
  15. ;        11.01.00 pedantic mode and skipping tracks added
  16. ;             error handling changed
  17. ;        24.02.00 multiple tracks can be skipped now (taken from wwarp ;-)
  18. ;        21.07.00 bug: retry after diskchange fixed (Andreas Falkenhahn)
  19. ;        22.07.00 option 'Name' added (Andreas Falkenhahn)
  20. ;        11.06.03 bug with device inhibit fixed (JOTD)
  21. ;  :Requires.    OS V37+
  22. ;  :Copyright.    © 1996,1997,1998,1999,2000,2003 Bert Jahn, All Rights Reserved
  23. ;  :Language.    68000 Assembler
  24. ;  :Translator.    Barfly V2.16
  25. ;  :To Do.
  26. ;---------------------------------------------------------------------------*
  27. ;##########################################################################
  28.  
  29.     INCDIR    Includes:
  30.     INCLUDE    lvo/exec.i
  31.     INCLUDE    exec/execbase.i
  32.     INCLUDE    exec/io.i
  33.     INCLUDE    exec/memory.i
  34.     INCLUDE    lvo/dos.i
  35.     INCLUDE    dos/dos.i
  36.     INCLUDE    devices/trackdisk.i
  37.  
  38.     INCLUDE    macros/ntypes.i
  39.     INCLUDE    macros/mulu32.i
  40.  
  41. ;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  42.  
  43. MAXTRACKS    = 160
  44.  
  45.     STRUCTURE    Globals,0
  46.         APTR    gl_execbase
  47.         APTR    gl_dosbase
  48.         ULONG    gl_stdin
  49.         APTR    gl_rdargs
  50.         LABEL    gl_rdarray
  51.         ULONG    gl_rd_device
  52.         ULONG    gl_rd_name
  53.         ULONG    gl_rd_st
  54.         ULONG    gl_rd_size
  55.         ULONG    gl_rd_fdisk
  56.         ULONG    gl_rd_ldisk
  57.         ULONG    gl_rd_pedantic
  58.         ULONG    gl_rc
  59.         STRUCT    gl_skip,MAXTRACKS
  60.         ALIGNLONG
  61.         LABEL    gl_SIZEOF
  62.  
  63. ;##########################################################################
  64.  
  65. GL    EQUR    A4        ;a4 ptr to Globals
  66. LOC    EQUR    A5        ;a5 for local vars
  67. CPU    =    68000
  68.  
  69. Version     = 0
  70. Revision = 21
  71.  
  72.     IFD BARFLY
  73.     PURE
  74.     OUTPUT    C:DIC
  75.     BOPT    O+                ;enable optimizing
  76.     BOPT    OG+                ;enable optimizing
  77.     BOPT    ODd-                ;disable mul optimizing
  78.     BOPT    ODe-                ;disable mul optimizing
  79.     ENDC
  80.  
  81.     IFND    .passchk
  82.     DOSCMD    "WDate >T:date"
  83. .passchk
  84.     ENDC
  85.  
  86. VER    MACRO
  87.         sprintx    "DIC %ld.%ld ",Version,Revision
  88.     INCBIN    "T:date"
  89.     ENDM
  90.  
  91.         bra    .start
  92.         dc.b    0,"$VER: "
  93.         VER
  94.         dc.b    0
  95.         dc.b    "$Id: DIC.asm 0.21 2003/06/14 20:17:42 wepl Exp wepl $",10,0
  96.     EVEN
  97. .start
  98.  
  99. ;##########################################################################
  100.  
  101.         move.l    #gl_SIZEOF,d0
  102.         move.l    #MEMF_CLEAR,d1
  103.         move.l    (4).w,a6
  104.         jsr    (_LVOAllocMem,a6)
  105.         tst.l    d0
  106.         beq    .nostrucmem
  107.         move.l    d0,GL
  108.         move.l    a6,(gl_execbase,GL)
  109.         move.l    #RETURN_FAIL,(gl_rc,GL)
  110.  
  111.         move.l    #37,d0
  112.         lea    (_dosname),a1
  113.         move.l    (gl_execbase,GL),a6
  114.         jsr    (_LVOOpenLibrary,a6)
  115.         move.l    d0,(gl_dosbase,GL)
  116.         beq    .nodoslib
  117.  
  118.         lea    (_ver),a0
  119.         bsr    _Print
  120.  
  121.         lea    (_defdev),a0
  122.         move.l    a0,(gl_rd_device,GL)
  123.  
  124.         lea    (_template),a0
  125.         move.l    a0,d1
  126.         lea    (gl_rdarray,GL),a0
  127.         move.l    a0,d2
  128.         moveq    #0,d3
  129.         move.l    (gl_dosbase,GL),a6
  130.         jsr    (_LVOReadArgs,a6)
  131.         move.l    d0,(gl_rdargs,GL)
  132.         bne    .argsok
  133.         lea    (_readargs),a0
  134.         bsr    _PrintErrorDOS
  135.         bra    .noargs
  136. .argsok
  137.         move.l    (gl_rd_device,GL),a0
  138.         tst.b    (a0)
  139.         beq    .baddev
  140. .chkdev        move.b    (a0)+,d0
  141.         tst.b    (a0)
  142.         bne    .chkdev
  143.         cmp.b    #":",d0
  144.         beq    .devok
  145. .baddev        lea    (_baddevname),a0
  146.         bsr    _Print
  147.         bra    .badargs
  148. .devok
  149.         move.l    (gl_rd_size,GL),d0
  150.         beq    .01
  151.         move.l    d0,a0
  152.         bsr    _etoi
  153.         tst.b    (a0)
  154.         beq    .0
  155.         lea    (_badsize),a0
  156.         bsr    _Print
  157.         bra    .badargs
  158. .0        move.l    d0,(gl_rd_size,GL)
  159.         lea    (_withsize),a0
  160.         move.l    d0,-(a7)
  161.         move.l    d0,-(a7)
  162.         move.l    a7,a1
  163.         bsr    _PrintArgs
  164.         addq.l    #8,a7
  165. .01
  166.         moveq    #1,d1            ;default
  167.         move.l    (gl_rd_fdisk,GL),d0
  168.         beq    .1
  169.         move.l    d0,a0
  170.         move.l    (a0),d1
  171. .1        move.l    d1,(gl_rd_fdisk,GL)
  172.  
  173.         moveq    #-1,d1            ;default - no limit
  174.         move.l    (gl_rd_ldisk,GL),d0
  175.         beq    .2
  176.         move.l    d0,a0
  177.         move.l    (a0),d1
  178. .2        move.l    d1,(gl_rd_ldisk,GL)
  179.  
  180.         tst.l    (gl_rd_name,GL)
  181.         beq    .noname
  182.         moveq    #1,d0
  183.         move.l    d0,(gl_rd_fdisk,GL)
  184.         move.l    d0,(gl_rd_ldisk,GL)
  185. .noname
  186.  
  187.     ;parse tracks
  188.         move.l    (gl_rd_st,GL),a0
  189.         move.l    a0,d0
  190.         beq    .pt_end
  191.  
  192. .pt_loop    bsr    .pt_getnum
  193.         move.b    (a0)+,d1
  194.         beq    .pt_single
  195.         cmp.b    #",",d1
  196.         beq    .pt_single
  197.         cmp.b    #"-",d1
  198.         beq    .pt_area
  199.         cmp.b    #"*",d1
  200.         beq    .pt_step
  201.         bra    .pt_err
  202.  
  203. .pt_single    st    (gl_skip,GL,d0.w)
  204. .pt_check    tst.b    d1
  205.         beq    .pt_end
  206.         cmp.b    #",",d1
  207.         beq    .pt_loop
  208.         bra    .pt_err
  209.         
  210. .pt_step    move.l    d0,d2            ;D2 = start
  211.         move.l    #MAXTRACKS-1,d3        ;D3 = last
  212. .pt_step0    bsr    .pt_getnum        ;D0 = skip
  213.         tst.l    d0
  214.         ble    .pt_err
  215. .pt_step1    cmp.l    d2,d3
  216.         blo    .pt_err
  217. .pt_step_l    st    (gl_skip,GL,d2.w)
  218.         add.l    d0,d2
  219.         cmp.l    d2,d3
  220.         bhs    .pt_step_l
  221.         move.b    (a0)+,d1
  222.         bra    .pt_check
  223.  
  224. .pt_area    move.l    d0,d2            ;D2 = start
  225.         bsr    .pt_getnum
  226.         move.l    d0,d3            ;D3 = last
  227.         moveq    #1,d0            ;D0 = skip
  228.         cmp.b    #"*",(a0)
  229.         bne    .pt_step1
  230.         addq.l    #1,a0
  231.         bra    .pt_step0
  232.  
  233. .pt_getnum    move.l    (a7)+,a1
  234.         move.l    a0,a3
  235.         bsr    _atoi
  236.         cmp.l    a0,a3
  237.         beq    .pt_err
  238.         cmp.l    #MAXTRACKS,d0
  239.         bhs    .pt_err
  240.         jmp    (a1)
  241.  
  242. .pt_err        lea    (_txt_badtracks),a0
  243.         bsr    _Print
  244.         bra    .badargs
  245.  
  246. .pt_end
  247.         move.l    (gl_dosbase,GL),a6
  248.         jsr    (_LVOInput,a6)
  249.         move.l    d0,(gl_stdin,GL)
  250.  
  251.         move.l    #RETURN_ERROR,(gl_rc,GL)
  252.         bsr    _Main
  253. .badargs
  254.         move.l    (gl_rdargs,GL),d1
  255.         move.l    (gl_dosbase,GL),a6
  256.         jsr    (_LVOFreeArgs,a6)
  257. .noargs
  258.         move.l    (gl_dosbase,GL),a1
  259.         move.l    (gl_execbase,GL),a6
  260.         jsr    (_LVOCloseLibrary,a6)
  261. .nodoslib
  262.         move.l    (gl_rc,GL),d7
  263.  
  264.         move.l    #gl_SIZEOF,d0
  265.         move.l    GL,a1
  266.         move.l    (gl_execbase,GL),a6
  267.         jsr    (_LVOFreeMem,a6)
  268.  
  269.         move.l    d7,d0
  270.         rts
  271.  
  272. .nostrucmem    moveq    #RETURN_FAIL,d0
  273.         rts
  274.  
  275. ;##########################################################################
  276.  
  277.     INCDIR    Sources:
  278.     INCLUDE    dosio.i
  279.         PrintLn
  280.         PrintArgs
  281.         Print
  282.         FlushOutput
  283.         CheckBreak
  284.         GetKey
  285.     INCLUDE    files.i
  286.         SaveFileMsg
  287.     INCLUDE    strings.i
  288.         CopyString
  289.         FormatString
  290.         DoString
  291.         etoi
  292.     INCLUDE    devices.i
  293.         GetDeviceInfo
  294.     INCLUDE    error.i
  295.         PrintErrorTD
  296.  
  297. ;++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  298.  
  299. _Main        move.l    (gl_rd_device,GL),d1
  300.         moveq    #-1,d2
  301.         move.l    (gl_dosbase,GL),a6
  302.         jsr    (_LVOInhibit,a6)
  303.         tst.l    d0
  304.         beq    .errinhibit
  305.  
  306.         move.l    (gl_rd_fdisk,GL),d7    ;d7 disknumber
  307.         subq.l    #1,d7
  308. .nextdisk    addq.l    #1,d7
  309.         cmp.l    (gl_rd_ldisk,GL),d7
  310.         bhi    .success
  311.  
  312.     ;check if interactive console
  313.         move.l    (gl_stdin,GL),d1
  314.         move.l    (gl_dosbase,GL),a6
  315.         jsr    (_LVOIsInteractive,a6)
  316.         tst.l    d0
  317.         beq    .readdisk
  318.  
  319.     ;prompt user to insert disk
  320.         lea    (_insdisk),a0
  321.         move.l    (gl_rd_device,GL),-(a7)
  322.         move.l    d7,-(a7)
  323.         move.l    a7,a1
  324.         bsr    _PrintArgs
  325.         addq.l    #8,a7
  326.         bsr    _FlushOutput
  327.         move.l    (gl_stdin,GL),d1
  328.         move.l    (gl_dosbase,GL),a6
  329.         jsr    (_LVOFlush,a6)
  330.         
  331.     ;wait for return
  332. .wait        bsr    _GetKey
  333.         cmp.b    #3,d0            ;^C ?
  334.         beq    .end
  335.         cmp.b    #13,d0            ;CR ?
  336.         bne    .wait
  337.         bsr    _PrintLn
  338.  
  339.     ;read the disk image
  340. .readdisk    move.l    (gl_rd_device,GL),a0
  341.         bsr    _LoadDisk
  342.         move.l    d1,d4            ;D4 = size
  343.         move.l    d0,d5            ;D5 = buffer
  344.         beq    .end
  345.         
  346. NAMEBUFLEN = 16
  347.  
  348.     ;save disk image
  349.         lea    (_filefmt),a0        ;fmt
  350.         move.l    d7,-(a7)
  351.         move.l    a7,a1            ;args
  352.         sub.l    #NAMEBUFLEN,a7
  353.         move.l    a7,a2            ;buffer
  354.         moveq    #NAMEBUFLEN,d0        ;bufsize
  355.         bsr    _FormatString
  356.         move.l    (gl_rd_name,GL),d0
  357.         beq    .noname
  358.         move.l    d0,a2
  359. .noname        move.l    d4,d0            ;size
  360.         tst.l    (gl_rd_size,GL)
  361.         beq    .s
  362.         cmp.l    (gl_rd_size,GL),d0
  363.         bls    .s
  364.         move.l    (gl_rd_size,GL),d0
  365. .s        move.l    d5,a0            ;buffer
  366.         move.l    a2,a1            ;filename
  367.         bsr    _SaveFileMsg
  368.         add.l    #NAMEBUFLEN+4,a7
  369.         move.l    d0,d2            ;save return code
  370.         move.l    d5,a1
  371.         move.l    (gl_execbase,GL),a6
  372.         jsr    (_LVOFreeVec,a6)
  373.         tst.l    d2
  374.         beq    .end            ;if save file has failed
  375.  
  376.         bra    .nextdisk
  377.  
  378. .success    clr.l    (gl_rc,GL)
  379.  
  380. .end        move.l    (gl_rd_device,GL),d1
  381.         moveq    #0,d2
  382.         move.l    (gl_dosbase,GL),a6
  383.         jsr    (_LVOInhibit,a6)
  384.         tst.l    d0
  385.         beq    .errinhibit
  386.         
  387.         rts
  388.  
  389. .errinhibit    lea    (_inhibit),a0
  390.         bra    _PrintErrorDOS
  391.  
  392. ;##########################################################################
  393. ;----------------------------------------
  394. ; read disk
  395. ; IN:    A0 = CPTR device name
  396. ; OUT:    D0 = APTR loaded buffer OR NIL
  397. ;    D1 = LONG size of buffer
  398.  
  399.     NSTRUCTURE    local_dodisk,0
  400.         NSTRUCT    ld_di,devi_SIZEOF        ;DeviceInfo
  401.         NSTRUCT    ld_devname,DEVNAMELEN        ;devicename without ":"
  402.         NLABEL    ld_SIZEOF
  403.  
  404. _LoadDisk    movem.l    d2-d7/a6,-(a7)
  405.         link    LOC,#ld_SIZEOF
  406.         moveq    #0,d7                ;D7 = returncode (bufptr)
  407.         moveq    #0,d6                ;D6 = bufsize
  408.         
  409.     ;remove ":" from device name
  410.         lea    (ld_devname,LOC),a1
  411.         moveq    #DEVNAMELEN-1,d0
  412. .c        move.b    (a0)+,(a1)+
  413.         dbeq    d0,.c
  414.         clr.b    -(a1)
  415.         clr.b    -(a1)                :remove ":"
  416.  
  417.     ;get geometry for device
  418.         lea    (ld_devname,LOC),a0
  419.         lea    (ld_di,LOC),a1
  420.         bsr    _GetDeviceInfo
  421.         tst.l    d0
  422.         beq    .nodevi
  423.  
  424.     ;print device name
  425.         lea    (_m_readdisk),a0
  426.         move.l    (ld_di+devi_Unit,LOC),-(a7)
  427.         pea    (ld_di+devi_Device,LOC)
  428.         pea    (ld_devname,LOC)
  429.         move.l    a7,a1
  430.         bsr    _PrintArgs
  431.         add.w    #12,a7
  432.         
  433.         move.l    (ld_di+devi_LowCyl,LOC),d2
  434.     IFEQ CPU-68020
  435.         mulu.l    (ld_di+devi_Surfaces,LOC),d2
  436.     ELSE
  437.         move.l    (ld_di+devi_Surfaces,LOC),d0
  438.         mulu32    d0,d2                    ;D2 = first track
  439.     ENDC
  440.  
  441.         move.l    (ld_di+devi_HighCyl,LOC),d3
  442.         sub.l    (ld_di+devi_LowCyl,LOC),d3
  443.         addq.l    #1,d3
  444.     IFEQ CPU-68020
  445.         mulu.l    (ld_di+devi_Surfaces,LOC),d3
  446.     ELSE
  447.         move.l    (ld_di+devi_Surfaces,LOC),d0
  448.         mulu32    d0,d3                    ;D3 = amount of tracks
  449.     ENDC
  450.  
  451.     IFEQ CPU-68020
  452.         move.l    (ld_di+devi_SizeBlock,LOC),d4
  453.         mulu.l    (ld_di+devi_BlocksPerTrack,LOC),d4
  454.     ELSE
  455.         move.l    (ld_di+devi_SizeBlock,LOC),d4
  456.         move.l    (ld_di+devi_BlocksPerTrack,LOC),d0
  457.         mulu32    d0,d4                    ;D4 = tracksize
  458.     ENDC
  459.  
  460.     ;print geometry
  461.         lea    (_m_diskgeo),a0
  462.         move.l    d3,d6
  463.         mulu32    d4,d6            ;disksize = cyls * heads * blktrk * blksize
  464.         move.l    d6,-(a7)
  465.         move.l    (ld_di+devi_HighCyl,LOC),-(a7)
  466.         move.l    (ld_di+devi_LowCyl,LOC),-(a7)
  467.         move.l    (ld_di+devi_BlocksPerTrack,LOC),-(a7)
  468.         move.l    (ld_di+devi_Surfaces,LOC),-(a7)
  469.         move.l    (ld_di+devi_SizeBlock,LOC),-(a7)
  470.         move.l    a7,a1
  471.         bsr    _PrintArgs
  472.         add.w    #6*4,a7
  473.  
  474.     ;calculate readlen / tracks
  475.         tst.l    (gl_rd_size,GL)
  476.         beq    .sok
  477.         cmp.l    (gl_rd_size,GL),d6
  478.         bls    .sok
  479.         moveq    #0,d3
  480.         moveq    #0,d6
  481. .add        addq.l    #1,d3                    ;D3 = amount of tracks
  482.         add.l    d4,d6                    ;D6 = bufsize
  483.         cmp.l    (gl_rd_size,GL),d6
  484.         blo    .add
  485. .sok
  486.         move.l    d6,d0
  487.         move.l    #MEMF_ANY,d1
  488.         move.l    (gl_execbase,GL),a6
  489.         jsr    (_LVOAllocVec,a6)
  490.         move.l    d0,d7
  491.         bne    .memok
  492.         moveq    #0,d0
  493.         lea    (_nomem),a0
  494.         lea    (_getdiskmem),a1
  495.         bsr    _PrintError
  496.         bra    .nomem
  497. .memok
  498.         lea    (ld_di+devi_Device,LOC),a0
  499.         move.l    a0,d0                    ;D0 = devicename
  500.         move.l    (ld_di+devi_Unit,LOC),d1        ;D1 = unit
  501.         move.l    d7,a1                    ;A1 = buffer
  502.         bsr    _ReadDisk
  503.         tst.l    d0
  504.         bne    .ok
  505.  
  506.         move.l    d7,a1
  507.         move.l    (gl_execbase,GL),a6
  508.         jsr    (_LVOFreeVec,a6)
  509.         moveq    #0,d6
  510.         moveq    #0,d7
  511. .ok
  512. .nomem
  513. .nodevi
  514.         move.l    d6,d1
  515.         move.l    d7,d0
  516.         unlk    LOC
  517.         movem.l    (a7)+,d2-d7/a6
  518.         rts
  519.  
  520. ;----------------------------------------
  521. ; Lesen Diskette
  522. ; IN:    D0 = APTR  device name
  523. ;    D1 = ULONG unit number
  524. ;    D2 = ULONG start track
  525. ;    D3 = ULONG tracks
  526. ;    D4 = ULONG bytes per track
  527. ;    A1 = APTR  buffer to read data in
  528. ;    GL = STRUCT globals
  529. ; OUT:    D0 = BOOL success
  530.  
  531.     NSTRUCTURE    local_readdisk,0
  532.         NAPTR    lrd_device
  533.         NULONG    lrd_unit
  534.         NAPTR    lrd_buffer
  535.         NAPTR    lrd_msgport
  536.         NBYTE    lrd_skipall
  537.         NALIGNLONG
  538.         LABEL    lrd_SIZEOF
  539.  
  540. _ReadDisk    movem.l    d2-d3/d7/a2/a6,-(a7)
  541.         link    LOC,#lrd_SIZEOF
  542.         move.l    d0,(lrd_device,LOC)
  543.         move.l    d1,(lrd_unit,LOC)
  544.         move.l    a1,(lrd_buffer,LOC)
  545.         sf    (lrd_skipall,LOC)
  546.         moveq    #0,d7                ;D7 = return (false)
  547.  
  548.         move.l    (gl_execbase,GL),a6        ;A6 = execbase
  549.         jsr    (_LVOCreateMsgPort,a6)
  550.         move.l    d0,(lrd_msgport,LOC)
  551.         bne    .portok
  552.         moveq    #0,d0
  553.         lea    (_noport),a0
  554.         sub.l    a1,a1
  555.         bsr    _PrintError
  556.         bra    .noport
  557. .portok        
  558.         move.l    (lrd_msgport,LOC),a0
  559.         move.l    #IOTD_SIZE,d0
  560.         jsr    (_LVOCreateIORequest,a6)
  561.         move.l    d0,a2                ;A2 = ioreq
  562.         tst.l    d0
  563.         bne    .ioreqok
  564.         moveq    #0,d0
  565.         lea    (_noioreq),a0
  566.         sub.l    a1,a1
  567.         bsr    _PrintError
  568.         bra    .noioreq
  569. .ioreqok
  570.         move.l    (lrd_device,LOC),a0
  571.         move.l    (lrd_unit,LOC),d0
  572.         move.l    a2,a1                ;ioreq
  573.         move.l    #0,d1                ;flags
  574.     move.l    d3,-(a7)                ;BUG in fucking mfm.device
  575.         jsr    (_LVOOpenDevice,a6)
  576.     move.l    (a7)+,d3                ;BUG in fucking mfm.device
  577.         tst.l    d0
  578.         beq    .deviceok
  579.         move.b    (IO_ERROR,a2),d0
  580.         lea    (_opendevice),a0
  581.         bsr    _PrintErrorTD
  582.         bra    .nodevice
  583. .deviceok
  584.  
  585.     ;get actual diskchange count
  586.         move.l    a2,a1                ;ioreq
  587.         move.w    #TD_CHANGENUM,(IO_COMMAND,a1)
  588.         jsr    (_LVODoIO,a6)
  589.         move.l    (IO_ACTUAL,a2),(IOTD_COUNT,a2)
  590.  
  591.         add.l    d2,d3                ;D3 = last track
  592.  
  593.         bsr    _PrintLn
  594. .loop        lea    (_diskprogress),a0        ;output progress
  595.         move.l    d3,-(a7)
  596.         sub.l    d2,(a7)
  597.         subq.l    #1,(a7)
  598.         move.l    d2,-(a7)
  599.         move.l    a7,a1
  600.         bsr    _PrintArgs
  601.         addq.l    #8,a7
  602.         
  603.     ;check for CTRL-C
  604.         bsr    _CheckBreak
  605.         tst.l    d0
  606.         bne    .break
  607.         
  608.     ;check if track should be skipped
  609.         tst.b    (gl_skip,GL,d2.w)
  610.         bne    .skip
  611.  
  612.     ;read the track
  613.         clr.b    (IO_ERROR,a2)
  614.         move.w    #ETD_READ,(IO_COMMAND,a2)
  615.         move.l    d4,(IO_LENGTH,a2)        ;bytes per track
  616.         move.l    d2,d0
  617.         mulu32    d4,d0
  618.         move.l    d0,(IO_OFFSET,a2)        ;begin at disk (offset)
  619.         add.l    (lrd_buffer,LOC),d0
  620.         move.l    d0,(IO_DATA,a2)            ;dest buf
  621.         move.l    a2,a1
  622.         move.l    (gl_execbase,GL),a6
  623.         jsr    (_LVODoIO,a6)
  624.         move.b    (IO_ERROR,a2),d0
  625.         beq    .readok
  626.         lea    (_readdisk),a0
  627.         bsr    _PrintErrorTD
  628.         
  629.         cmp.b    #TDERR_DiskChanged,(IO_ERROR,a2)
  630.         bne    .notchg
  631.         move.l    a2,a1                ;ioreq
  632.         move.w    #TD_CHANGENUM,(IO_COMMAND,a1)
  633.         jsr    (_LVODoIO,a6)
  634.         move.l    (IO_ACTUAL,a2),(IOTD_COUNT,a2)
  635. .notchg
  636.         tst.l    (gl_rd_pedantic,GL)
  637.         bne    .break
  638.         
  639.         tst.b    (lrd_skipall,LOC)
  640.         bne    .skip
  641.  
  642.         move.l    (gl_stdin,GL),d1
  643.         move.l    (gl_dosbase,GL),a6
  644.         jsr    (_LVOIsInteractive,a6)
  645.         tst.l    d0
  646.         beq    .skip
  647.  
  648.         lea    (_tryagain),a0
  649.         bsr    _Print
  650.         bsr    _FlushOutput
  651.         
  652. .wait        bsr    _GetKey
  653.         cmp.b    #3,d0                ;Ctrl-C
  654.         beq    .break
  655.         UPPER    d0
  656.         cmp.b    #"R",d0
  657.         beq    .waitend
  658.         cmp.b    #"S",d0
  659.         beq    .waitend
  660.         cmp.b    #"A",d0
  661.         beq    .waitend
  662.         cmp.b    #"Q",d0
  663.         beq    .waitend
  664.         cmp.b    #13,d0                ;Return
  665.         bne    .wait
  666.         
  667. .waitend    lsl.w    #8,d0
  668.         or.w    #10,d0
  669.         clr.w    -(a7)
  670.         move.w    d0,-(a7)
  671.         move.l    a7,a0
  672.         bsr    _Print
  673.         move.l    (a7)+,d0
  674.         rol.l    #8,d0
  675.         cmp.b    #"R",d0
  676.         beq    .loop
  677.         cmp.b    #"S",d0
  678.         beq    .skip
  679.         cmp.b    #"Q",d0
  680.         beq    .break
  681.         cmp.b    #13,d0                ;Return
  682.         beq    .break
  683.  
  684.     ;skip all errors
  685.         st    (lrd_skipall,LOC)
  686.  
  687. .skip
  688.     ;fill track data area with pattern "TDIC"
  689.         move.l    d2,d0
  690.         mulu32    d4,d0
  691.         add.l    (lrd_buffer,LOC),d0
  692.         move.l    d0,a0
  693.         move.l    d4,d0
  694.         lsr.l    #2,d0
  695. .fill        move.l    #"TDIC",(a0)+
  696.         subq.l    #1,d0
  697.         bne    .fill
  698.         
  699.     ;next track
  700. .readok        addq.l    #1,d2
  701.         cmp.l    d2,d3
  702.         bne    .loop
  703.  
  704.         bsr    _PrintLn
  705.         moveq    #-1,d7
  706. .break
  707.  
  708.     ;switch drive motor off
  709.         move.l    a2,a1
  710.         move.l    #0,(IO_LENGTH,a1)
  711.         move.w    #ETD_MOTOR,(IO_COMMAND,a1)
  712.         move.l    (gl_execbase,GL),a6
  713.         jsr    (_LVODoIO,a6)
  714.  
  715.         move.l    a2,a1
  716.         jsr    (_LVOCloseDevice,a6)
  717.         
  718. .nodevice    move.l    a2,a0
  719.         jsr    (_LVODeleteIORequest,a6)
  720.         
  721. .noioreq    move.l    (lrd_msgport,LOC),a0
  722.         jsr    (_LVODeleteMsgPort,a6)
  723.         
  724. .noport        move.l    d7,d0                ;return code
  725.         unlk    LOC
  726.         movem.l    (a7)+,d2-d3/d7/a2/a6
  727.         rts
  728.  
  729. ;##########################################################################
  730.  
  731. _defdev        dc.b    "DF0:",0
  732. _insdisk    dc.b    10,"Insert disk %ld into drive %s and press RETURN (^C to cancel) ...",0
  733. _tryagain    dc.b    "Retry/Skip/skip All/Quit (r/s/a/Q): ",0
  734. _filefmt    dc.b    "Disk.%ld",0
  735. _txt_badtracks    dc.b    "Invalid SKIPTRACK/K specification",10,0
  736.  
  737. ;Messages
  738. _m_readdisk    dc.b    "read from ",155,"1m%s",155,"22m: (%s %ld)",10,0
  739. _m_diskgeo    dc.b    "(blksize=%ld heads=%ld blktrk=%ld lcyl=%ld hcyl=%ld) size=%ld",10,0
  740. _m_savedisk    dc.b    "save disk as ",155,"3m%s ",155,"23m",10,0
  741. _m_savefile    dc.b    "save file ",155,"3m%s ",155,"23m",10,0
  742. _diskprogress    dc.b    11,155,"Kreading track %ld left %ld",10,0
  743. _withsize    dc.b    "limited reading of $%lx=%ld bytes",10,0
  744.  
  745. ; Errors
  746. _nomem        dc.b    "not enough free store",0
  747. _noport        dc.b    "can't create MessagePort",0
  748. _noioreq    dc.b    "can't create IO-Request",0
  749. _nodev        dc.b    "device doesn't exist",0
  750. _baddev        dc.b    "cannot handle this device",0
  751. _baddevname    dc.b    "specified device must have trailing colon",10,0
  752. _badsize    dc.b    "illegal argument for SIZE/K",10,0
  753.  
  754. ; Operationen
  755. _readargs    dc.b    "read arguments",0
  756. _inhibit    dc.b    "inhibit filesystem",0
  757. _getdiskmem    dc.b    "alloc mem for disk",0
  758. _readdisk    dc.b    "read disk",0
  759. _getdevinfo    dc.b    "get dev info",0
  760. _opendevice    dc.b    "open device",0
  761.  
  762. ;subsystems
  763. _dosname    DOSNAME
  764.  
  765. _template    dc.b    "DEVICE"        ;name of device (default "DF0:)
  766.         dc.b    ",NAME"            ;name of image, implies FD=1 and LD=1
  767.         dc.b    ",SKIPTRACK/K"        ;dont read these tracks
  768.         dc.b    ",SIZE/K"        ;number of bytes
  769.         dc.b    ",FD=FIRSTDISK/K/N"    ;number of first disk
  770.         dc.b    ",LD=LASTDISK/K/N"    ;number of last disk
  771.         dc.b    ",PEDANTIC/S"        ;quit on unreadable tracks
  772.         dc.b    0
  773.  
  774. _ver        VER
  775.         dc.b    " ",155,"1mD",155,"22misk ",155,"1mI",155,"22mmage ",155,"1mC",155,"22mreator by Bert Jahn"
  776.         dc.b    10,0
  777.  
  778. ;##########################################################################
  779.  
  780.     END
  781.  
  782.